//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-05-03  Jed Young  Creation
//

using chunmapModel
using chunmapView
using chunmapData
using slanData

**
** LayerFactory
**
class LayerFactory
{

//////////////////////////////////////////////////////////////////////////
// createGeometryLayer
//////////////////////////////////////////////////////////////////////////

  static VectorLayer createGeometryLayer(Geometry[] gs)
  {
    //if (gs.size == 0) return null

    // get Envelope
    eb := EnvelopeBuilder.makeNone
    gs.each |g|
    {
      eb.merge(g.envelope)
    }

    schema := Schema("Geometry", [,])

    fc := FeatureList
    {
      metadata = Metadata
      {
        name = "Geometry"
        type = gs.first.geometryType
        crs = CoordRef.defVal
      }
      it.schema = schema
      envelope = eb.toEnvelope
    }

    gs.each |g, i|
    {
      Feature f := ShapeFeature(schema, null)
      {
        geometry = g
        id = i
      }
      fc.add(f)
    }

    return VectorLayer.makeFeatureSet(fc)
  }
}